package com.baidu.mapapi;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.HashMap;

public class RouteOverlay extends ItemizedOverlay<OverlayItem>
{
  private ArrayList<b> a = null;
  private MapView b = null;
  private Context c = null;
  private DisplayMetrics d;
  private int e = 1;
  private HashMap<Integer, a> f;
  public MKRoute mRoute = null;

  public RouteOverlay(Activity paramActivity, MapView paramMapView)
  {
    super(null);
    this.c = paramActivity;
    this.b = paramMapView;
    this.d = new DisplayMetrics();
    paramActivity.getWindowManager().getDefaultDisplay().getMetrics(this.d);
    if (Mj.i <= 120)
    {
      this.e = 0;
      return;
    }
    if (Mj.i <= 180)
    {
      this.e = 1;
      return;
    }
    this.e = 2;
  }

  void a(int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    this.f.clear();
  }

  public void animateTo()
  {
    if (size() > 0)
      onTap(0);
  }

  protected OverlayItem createItem(int paramInt)
  {
    char[] arrayOfChar = { 108, 109, 104 };
    String[] arrayOfString = { "start", "end", "foot", "car", "bus" };
    b localb = (b)this.a.get(paramInt);
    OverlayItem localOverlayItem = new OverlayItem(localb.b, localb.a, null);
    StringBuilder localStringBuilder = new StringBuilder(32);
    if ((localb.c == 0) || (localb.c == 1) || (localb.c == 4))
      localStringBuilder.append("icon_nav_").append(arrayOfString[localb.c]).append('_').append(arrayOfChar[this.e]).append(".png");
    for (Drawable localDrawable = k.a(this.c, localStringBuilder.toString()); (localb.c == 0) || (localb.c == 1); localDrawable = k.a(this.c, localStringBuilder.toString(), 30 * localb.d))
    {
      localOverlayItem.setMarker(boundCenterBottom(localDrawable));
      return localOverlayItem;
      localStringBuilder.append("icon_direction_").append(arrayOfChar[this.e]).append(".png");
    }
    localOverlayItem.setMarker(boundCenter(localDrawable));
    return localOverlayItem;
  }

  public boolean draw(Canvas paramCanvas, MapView paramMapView, boolean paramBoolean, long paramLong)
  {
    Projection localProjection = paramMapView.getProjection();
    ((Activity)this.c).getWindowManager().getDefaultDisplay().getMetrics(this.d);
    int i = paramMapView.getZoomLevel();
    a locala1;
    a locala2;
    if (this.mRoute != null)
    {
      ArrayList localArrayList1 = this.mRoute.getArrayPoints();
      ArrayList localArrayList2 = this.mRoute.a;
      if ((localArrayList1 != null) && (localArrayList1.size() > 0))
      {
        locala1 = (a)this.f.get(Integer.valueOf(i));
        if (locala1 != null)
          break label1009;
        locala2 = new a();
        int j = localArrayList1.size();
        ArrayList localArrayList3 = new ArrayList();
        for (int k = 0; k < j; k++)
        {
          k.a((ArrayList)localArrayList1.get(k), (ArrayList)localArrayList2.get(k), i, localArrayList3);
          int i15 = localArrayList3.size();
          for (int i16 = 0; i16 < i15; i16++)
          {
            Point localPoint5 = new Point();
            paramMapView.a.a((GeoPoint)localArrayList3.get(i16), localPoint5);
            locala2.b.add(localPoint5);
          }
        }
        locala2.a.setLatitudeE6(paramMapView.getMapCenter().getLatitudeE6());
        locala2.a.setLongitudeE6(paramMapView.getMapCenter().getLongitudeE6());
        this.f.put(Integer.valueOf(i), locala2);
      }
    }
    label948: label998: label1009: for (a locala3 = locala2; ; locala3 = locala1)
    {
      int m = locala3.b.size();
      int n;
      int i1;
      Point localPoint1;
      Point localPoint2;
      int i6;
      int i7;
      int i8;
      if (m > 1)
      {
        n = 0;
        i1 = 0;
        localPoint1 = new Point();
        localPoint2 = new Point();
        Paint localPaint = new Paint();
        localPaint.setAntiAlias(true);
        localPaint.setStrokeWidth(6.0F);
        localPaint.setColor(Color.rgb(58, 107, 189));
        localPaint.setAlpha(192);
        Point localPoint3 = new Point();
        Point localPoint4 = new Point();
        localProjection.toPixels(paramMapView.getMapCenter(), localPoint3);
        localProjection.toPixels(locala3.a, localPoint4);
        int i2 = localPoint3.x - localPoint4.x;
        int i3 = localPoint3.y - localPoint4.y;
        int i4 = i2 - paramMapView.b.c;
        int i5 = i3 - paramMapView.b.d;
        localPoint1.x = ((Point)locala3.b.get(0)).x;
        localPoint1.y = ((Point)locala3.b.get(0)).y;
        if (this.b.b.e != 1.0D)
        {
          int i13 = (int)(0.5D + (localPoint1.x - this.b.b.f) * this.b.b.e);
          int i14 = (int)(0.5D + (localPoint1.y - this.b.b.g) * this.b.b.e);
          localPoint1.x = (i13 + this.b.b.f);
          localPoint1.y = (i14 + this.b.b.g);
        }
        localPoint1.x -= i4;
        localPoint1.y -= i5;
        i6 = 1;
        if (i6 < m)
        {
          localPoint2.x = ((Point)locala3.b.get(i6)).x;
          localPoint2.y = ((Point)locala3.b.get(i6)).y;
          if (this.b.b.e != 1.0D)
          {
            int i11 = (int)(0.5D + (localPoint2.x - this.b.b.f) * this.b.b.e);
            int i12 = (int)(0.5D + (localPoint2.y - this.b.b.g) * this.b.b.e);
            localPoint2.x = (i11 + this.b.b.f);
            localPoint2.y = (i12 + this.b.b.g);
          }
          localPoint2.x -= i4;
          localPoint2.y -= i5;
          if (!k.a(localPoint1, localPoint2, this.d.widthPixels, this.d.heightPixels))
            break label948;
          paramCanvas.drawLine(localPoint1.x, localPoint1.y, localPoint2.x, localPoint2.y, localPaint);
          i7 = 1;
          i8 = n;
        }
      }
      while (true)
      {
        localPoint1.x = localPoint2.x;
        localPoint1.y = localPoint2.y;
        if (i8 > 50)
        {
          int i9;
          do
          {
            if (i < 3)
              break;
            return super.draw(paramCanvas, paramMapView, paramBoolean, paramLong);
            if (i1 != 1)
              break label998;
            i9 = n + 1;
          }
          while (i9 > 50);
          int i10 = i1;
          i8 = i9;
          i7 = i10;
        }
        else
        {
          i6++;
          n = i8;
          i1 = i7;
          break;
          return true;
          i7 = i1;
          i8 = n;
        }
      }
    }
  }

  protected boolean onTap(int paramInt)
  {
    OverlayItem localOverlayItem = getItem(paramInt);
    this.b.getController().animateTo(localOverlayItem.mPoint);
    if (localOverlayItem.mTitle != null)
      Toast.makeText(this.c, localOverlayItem.mTitle, 1).show();
    super.onTap(paramInt);
    return true;
  }

  public void setData(MKRoute paramMKRoute)
  {
    int i = 2;
    if (paramMKRoute == null)
      return;
    this.mRoute = paramMKRoute;
    this.a = new ArrayList();
    if (this.mRoute.getRouteType() == 1)
      i = 3;
    while (true)
    {
      GeoPoint localGeoPoint1 = this.mRoute.getStart();
      if (localGeoPoint1 != null)
      {
        b localb1 = new b(null);
        localb1.b = localGeoPoint1;
        localb1.c = 0;
        this.a.add(localb1);
      }
      int j = paramMKRoute.getNumSteps();
      if (j != 0)
      {
        if (this.a.size() > 0)
          ((b)this.a.get(0)).a = paramMKRoute.getStep(0).getContent();
        int k = 1;
        while (true)
          if (k < j - 1)
          {
            MKStep localMKStep = paramMKRoute.getStep(k);
            b localb3 = new b(null);
            localb3.b = localMKStep.getPoint();
            localb3.a = localMKStep.getContent();
            localb3.c = i;
            localb3.d = localMKStep.a();
            this.a.add(localb3);
            k++;
            continue;
            if (this.mRoute.getRouteType() == i)
              break;
            if (this.mRoute.getRouteType() != 3)
              break label298;
            i = 4;
            break;
          }
      }
      GeoPoint localGeoPoint2 = this.mRoute.getEnd();
      if (localGeoPoint2 != null)
      {
        b localb2 = new b(null);
        localb2.b = localGeoPoint2;
        localb2.c = 1;
        this.a.add(localb2);
      }
      this.f = new HashMap();
      super.populate();
      return;
      label298: i = 0;
    }
  }

  public int size()
  {
    if (this.a == null)
      return 0;
    return this.a.size();
  }

  class a
  {
    public GeoPoint a = new GeoPoint(0, 0);
    public ArrayList<Point> b = new ArrayList();

    public a()
    {
    }
  }

  private class b
  {
    public String a;
    public GeoPoint b;
    public int c;
    public int d;

    private b()
    {
    }
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.baidu.mapapi.RouteOverlay
 * JD-Core Version:    0.6.2
 */